#include <bits/stdc++.h>
using namespace std;
int T,n,m,L,vl,num,po,ne,cnt,ans;
int d[100010],v[100010],a[100010],p[1000010],h[100010],c[100010];
bool bo;
bool b[3010][3010];
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
void dfs(int dep,int x,int cnt){
    if(cnt>=x){
        int t=0;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=cnt; j++){
                if(b[i][c[j]]){
                    t++;
                    break;
                }
            }
        }
        if(t==ans) bo=1;
        return ;
    }
    if(dep>m) return ;
    if(bo) return ;
    c[cnt+1]=dep;
    dfs(dep+1,x,cnt+1);
    dfs(dep+1,x,cnt);
}
bool check(int x){
    bo=0;
    dfs(1,x,0);
    return bo;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>vl;
        num=0,po=0,ne=0,cnt=0;
        for(int i=1; i<=n; i++){
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]==0) num++;
            else if(a[i]>0) po++;
            else ne++;
        }
        for(int i=1; i<=m; i++) cin>>p[i];
        if(num==n){
            cnt=0;
            for(int i=1; i<=n; i++){
                if(d[i]<=p[m]&&v[i]>vl) cnt++;
            }
            if(cnt>0) cout<<cnt<<" "<<m-1<<endl;
            else cout<<cnt<<" "<<m<<endl;
            continue;
        }
        if(po==n){
            cnt=0;
            for(int i=1; i<=n; i++){
                if(d[i]<=p[m]&&sqrt(v[i]*v[i]*1.0+2*a[i]*(p[m]-d[i])*1.0)>vl*1.0) cnt++;
            }
            if(cnt>0) cout<<cnt<<" "<<m-1<<endl;
            else cout<<cnt<<" "<<m<<endl;
            continue;
        }
        bool fl;
        ans=0;
        for(int i=1; i<=n; i++){
            fl=0;
            for(int j=1; j<=m; j++){
                if(d[i]<=p[j]&&v[i]*v[i]*1.0+2*a[i]*(p[j]-d[i])*1.0>0&&sqrt(v[i]*v[i]*1.0+2*a[i]*(p[j]-d[i])*1.0)>vl*1.0){
                    b[i][j]=1;
                    fl=1;
                }
                else b[i][j]=0;
            }
            if(fl) ans++;
        }
        int l=0,r=m;
        while(l<=r){
            int mid=l+r>>1;
            if(check(mid)) r=mid-1;
            else l=mid+1;
        }
        cout<<ans<<" "<<m-l<<endl;
    }
    return 0;
}